//
//  HydrantAnnotation.m
//  MapProject
//

//

#import "HydrantAnnotation.h"
#define CLASS_D_MINIMUM 0
#define CLASS_D_MAXIMUM 500
#define CLASS_C_MAXIMUM 1000
#define CLASS_B_MAXIMUM 1499
#define CLASS_A_MINIMUM 1500

@implementation HydrantAnnotation
@synthesize nfpaClass=nfpaClass_;
@synthesize address=address_;
@synthesize coordinate, subtitle, title;
@synthesize hydrantId=hydrantId_;
@synthesize remarks=remarks_;

///initializes annotation with Hydrant data
- (id) initWithDictionary:(NSDictionary *) dict
{
	self = [super init];
	if (self != nil) {
		NSString *hydrantTitle= nil;
		coordinate.latitude = [[dict objectForKey:@"LAT"] doubleValue];
		coordinate.longitude = [[dict objectForKey:@"LON"] doubleValue];
		int gpm =0;
		gpm=[[dict objectForKey:@"GPM"]intValue];
		if (gpm>CLASS_D_MINIMUM && gpm<CLASS_D_MAXIMUM) {
			hydrantTitle=@"D";
		}else if (gpm>=CLASS_D_MAXIMUM && gpm <CLASS_C_MAXIMUM) {
			hydrantTitle=@"C";
		}else if (gpm>=CLASS_C_MAXIMUM && gpm <CLASS_A_MINIMUM) {
			hydrantTitle=@"B";
		}else if (gpm>=CLASS_A_MINIMUM) {
			hydrantTitle=@"A";
		}else{
			hydrantTitle=@"I";
						
		}
		NSString *nfpaClassPrefix= [[NSString alloc]initWithString:@"NFPA Class "];
		if (![hydrantTitle isEqualToString:@"I"]){
			self.title=[nfpaClassPrefix stringByAppendingString:hydrantTitle];
		}else {
			self.title=@"Inactive";
		}
		self.subtitle = [dict objectForKey:@"ADDRESS"];
		self.hydrantId = [dict objectForKey:@"HYDRANT_ID"];
		self.remarks=[dict objectForKey:@"REMARKS"];
		[nfpaClassPrefix release];
	}
	return self;
}
- (void)dealloc {
	[hydrantId_ release];
	[remarks_ release];
	[title release];
	[subtitle release];
    [super dealloc];
}


@end
